/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.kyle.bbdroid;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 *
 * @author kyle
 */
public class httpHandler {
    
    public String getHtml(String urlStr){
    
        String string = null;
        try {
            
            URL url = new URL(urlStr);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            InputStreamReader isr = new InputStreamReader(urlConnection.getInputStream());
            BufferedReader reader = new BufferedReader(isr);
            
            StringBuffer sb = new StringBuffer();
            
            while((string = reader.readLine()) != null){
                sb.append(string).append("\n");
            }
            
            isr.close();
            
            string = sb.toString();
            
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            
        }
    
        return string;
    }
    
    public CharSequence getTagContent(String html, String tag){
        
        CharSequence title = html.subSequence(html.indexOf("<"+ tag + ">") + tag.length() + 2, html.indexOf("</" + tag + ">"));
        
        return title;
    }
    
}
